﻿using AllIsWell.Core.Models;
using AllIsWell.Tests.TestData;
using NUnit.Framework;

namespace AllIsWell.Web.Tests.Controllers.PageControllerTests
{
    [TestFixture]
    class CreatePageOnPost : PageControllerTest
    {
        private Page _page;

        [SetUp]
        public void SetUp()
        {
            _page = PageSeed.GetPage();
            PageServiceMock.Setup(service => service.CreatePage(_page)).Returns(_page);
        }

        [Test]
        public void ShouldCreatePageUsingPageService()
        {
            var newPage = PageController.CreatePage(_page);
            
            Assert.IsNotNull(newPage);
        }

        [Test]
        public void ShouldRedirectToGreetUserAction()
        {
            var redirectToRouteResult = PageController.CreatePage(_page);

            Assert.AreEqual(1, redirectToRouteResult.RouteValues.Count);
            Assert.IsTrue(redirectToRouteResult.RouteValues.ContainsKey("action"));
            Assert.AreEqual("GreetUser", redirectToRouteResult.RouteValues["action"]);
        }

        [Test]
        public void ShouldPutGreetingMessageOfDestinyInTempdata()
        {
            var destiny = DestinySeed.GetDestiny(1);
            destiny.GreetingMessage = "Have a nice day";
            _page.Destiny = destiny;
            PageServiceMock.Setup(service => service.CreatePage(_page)).Returns(_page);

            PageController.CreatePage(_page);

            Assert.AreEqual("Have a nice day", PageController.TempData["GreetingMessage"]);
        }
    }
}